home *** CD-ROM | disk | FTP | other *** search
/ FM Towns: Free Software Collection 11 / FM Towns Free Software Collection 11.iso / t_os / lib / objcol2 / src / strin.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-08-10  |  3.7 KB  |  200 lines

  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <ctype.h>
  4. #include <egb.h>
  5. #include "symbol.h"
  6.  
  7. #define    ERR        1
  8. #define    NOERR    0
  9.  
  10. #include "strindat.c"
  11.  
  12. static int    ST_x = 0;
  13. static int    ST_y = 0;
  14. static char    *egbwork;
  15.  
  16. int        ST_locate( int, int );
  17. int        ST_inputStrings( char *, char *, int, const char * );
  18. static void    strcpy2( char *s1, const char *s2, char *buf );
  19. static void    strprint( char *buf, int dsp, int cur );
  20.  
  21. int        ST_locate( int x, int y )
  22. {
  23.     if( x<0 || x>367 || y<0 || y>433 )
  24.         return ERR;
  25.  
  26.     ST_x = x;
  27.     ST_y = y;
  28.  
  29.     return NOERR;
  30. }
  31.  
  32. static void    strcpy2( char *s1, const char *s2, char *buf )
  33. {
  34.     strcpy( buf, s2 );
  35.  
  36.     while( *buf )
  37.         *s1++ = *buf++;
  38.  
  39.     *s1 = '\0';
  40.  
  41.     return;
  42. }
  43.  
  44. static void    strprint( char *buf, int dsp, int cur )
  45. {
  46.     int        i;
  47.     char    printbuf[33];
  48.  
  49.     printbuf[32] = '\0';
  50.     EGB_paintMode( egbwork, 0x22 );
  51.     EGB_foreColor( egbwork, 0 );
  52.     EGB_paintColor( egbwork, 0 );
  53.     EGB_box( egbwork, ST_x+8, ST_y+25, ST_x+263, ST_y+40 );
  54.  
  55.     for( i=0; i<32; i++ )
  56.     {
  57.         printbuf[i] = *(buf+dsp+i);
  58.  
  59.         if( *(buf+dsp+i) == 0 )
  60.             break;
  61.     }
  62.  
  63.     EGB_foreColor( egbwork, 10 );
  64.     EGB_singleLine( egbwork, (ST_x+8+(cur-dsp)*8), (ST_y+25), (ST_x+8+(cur-dsp)*8), (ST_y+40) );
  65.  
  66.     EGB_foreColor( egbwork, 15 );
  67.     symbol( egbwork, ST_x+8, ST_y+40, printbuf );
  68.  
  69.     return;
  70. }
  71.  
  72. int        ST_inputStrings( char *w, char *buf, int size, const char *mes )
  73. {
  74.     int        ch,ec,cur,len,dsp,ret,i;
  75.     char    gbuf[6256],usrbuf[size],mes_[33];
  76.  
  77.     cur = 0;
  78.     len = 0;
  79.     dsp = 0;
  80.     egbwork = w;
  81.  
  82.     EGB_getRect( egbwork, gbuf, ST_x, ST_y, ST_x+271, ST_y+45 );
  83.     EGB_putRect( egbwork, 0, ST_grp_data, ST_x, ST_y, 271+ST_x, 45+ST_y );
  84.  
  85.     EGB_foreColor( egbwork, 8 );
  86.     strcpy( mes_, mes );
  87.     mes_[32] = '\0';
  88.     symbol( egbwork, ST_x+8, ST_y+20, mes_ );
  89.  
  90.     for( i=0; i<size; i++ )
  91.         buf[i] = 0;
  92.  
  93.     while(1)
  94.     {
  95.         ch = KYB_read( 1, &ec );
  96.         if( ( ch & 0xff00 ) == 0xff00 )
  97.             continue;
  98.         ch &= 0xff;
  99.  
  100.         if( ch>0x1f && ch<0x7f )    /* 文字の判定 */
  101.         {
  102.             if( len+1 < size )    /* 最後に'\0'を加える事を考えての判定 */
  103.             {
  104.                 strcpy2( buf+cur+1, buf+cur, usrbuf );
  105.                 *(buf+cur) = (char)ch;
  106.                 if( dsp+31 == cur )
  107.                     dsp ++;
  108.                 cur ++;
  109.                 len ++;
  110.                 strprint( buf, dsp, cur );
  111.             }
  112.         }
  113.         else
  114.         {
  115.             ec &= 0xff14;
  116.             switch( ec )
  117.             {
  118.                 case 0x4500:
  119.                 case 0x1d00:
  120.                 case 0x7300:
  121.                     /* 入力終了 */
  122.                     *(buf+len) = '\0';
  123.                     ret = len;
  124.                     goto END;
  125.                 case 0x0100:
  126.                 case 0x7200:
  127.                     /* 入力終了(取消) */
  128.                     ret = -3;
  129.                     goto END;
  130.                 case 0x4f00:
  131.                     /* 一文字左へ */
  132.                     if( cur > 0 )
  133.                     {
  134.                         if( dsp == cur )
  135.                             dsp --;
  136.                         cur --;
  137.                         strprint( buf, dsp, cur );
  138.                     }
  139.                     break;
  140.                 case 0x4f04:
  141.                     /* 最左端へ */
  142.                     if( cur > 0 )
  143.                     {
  144.                         cur = 0;
  145.                         dsp = 0;
  146.                         strprint( buf, dsp, cur );
  147.                     }
  148.                     break;
  149.                 case 0x5100:
  150.                     /* 一文字右へ */
  151.                     if( cur < len )
  152.                     {
  153.                         if( dsp+31 == cur )
  154.                             dsp ++;
  155.                         cur ++;
  156.                         strprint( buf, dsp, cur );
  157.                     }
  158.                     break;
  159.                 case 0x5104:
  160.                     /* 最右端へ */
  161.                     if( cur < len )
  162.                     {
  163.                         cur = len;
  164.                         if( cur > dsp + 31 )
  165.                             dsp = cur - 31;
  166.                         strprint( buf, dsp, cur );
  167.                     }
  168.                     break;
  169.                 case 0x0f00:
  170.                     /* [BS] */
  171.                     if( cur > 0 )
  172.                     {
  173.                         if( dsp == cur )
  174.                             dsp --;
  175.                         strcpy2( buf+cur-1, buf+cur, usrbuf );
  176.                         len --;
  177.                         cur --;
  178.                         strprint( buf, dsp, cur );
  179.                     }
  180.                     break;
  181.                 case 0x4b00:
  182.                     /* [DEL] */
  183.                     if( cur < len )
  184.                     {
  185.                         strcpy2( buf+cur, buf+cur+1, usrbuf );
  186.                         len --;
  187.                         strprint( buf, dsp, cur );
  188.                     }
  189.                     break;
  190.             }
  191.         }
  192.     }
  193.  
  194. END:
  195.  
  196.     EGB_putRect( egbwork, 0, gbuf, ST_x, ST_y, ST_x+271, ST_y+45 );
  197.  
  198.     return ret;
  199. }
  200.